/** @jsxImportSource @emotion/react */
import * as React from "react";
import {InspectRecordLayout, InternalItemProps, OriginalViewProps, useItemInputControl,} from "../../common/base";
import {assertNamesUnique, createItem,} from "../../common/eHelper";
import {useRecordListSubr} from "../../hook/useRecordListSub";
import {DeviceSurvey} from "../../elevator/editor";
import {useMedia} from "use-media";
import {Button, Text, TextArea, useToast} from "customize-easy-ui-component";
import {EditStorageContext} from "../../StorageContext";
import {render设备品种, render设备类别} from "../../common/render";
import {display额定是, display额定蒸发, input额定是} from "../rarelyVary";


const 施工许级选=['A1','A2','A3', ];
export const config设备概况 = [
  [['施工单位', '施单位'] ],
  [['许可级别', {n:'施许级',t:'l',l:施工许级选}], ['许可证编号', '施许可号'] ],
  [['使用单位', '_$使用单位'], ['制造单位', '_$制造单位']  ],
  [['设备类别', '_$设备类别',render设备类别], ['设备品种(名称)','_$设备品种',render设备品种]],
  [['产品型号', '_$型号'], ['产品编号', '_$出厂编号'], ],
  [['设备代码', '_$设备代码'], ['制造日期', '_$制造日期']],
  [['使用地点', '_$设备使用地点'] ],
  [['产品编号', '_$出厂编号'], ['设备代码', '_$设备代码']],
  [['使用单位内部编号','_$单位内部编号'], ['使用登记证编号', '_$使用证号'],  ],
  [['加热方式', '_$加热方式'], ['燃料种类', '_$燃料种类', ], ],
  // [['额定蒸发量', '_$额定蒸发量', 't/h'],   ['再热蒸汽流量', '_$再热蒸汽流量','t/h'],  ],   //=设计出口压力
  [[display额定蒸发, '_$额定蒸发量', input额定是], ['额定出口压力', '_$设计出口压力','MPa'] ],
  //设计出口温度 svp?.设出口温);     这不是用台账的:额定工作压力  ['额定温度', '_$额定温度','℃']
  [['额定出口温度', '_$出口温度','℃'], ['允许工作压力', '许工压','MPa'] ],
  //允许工作温度=额定温度；    台账3字段：耐压试验压力、水压试验压力、液压试验压力；
  [['允许工作温度', '_$额定温度','℃'], ['水（耐）压试验压力', '试验压','MPa'] ],
  [['说明：（可附页）', {n:'说明',t:'m'}] ],
];

//报错Cannot access 'EntranceSetup' before initialization 就因为import {display额定是, input额定是} from "../external/orcBase";
export const EntranceSetup =
    React.forwardRef((
        {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
    ) => {
      const atPrint = useMedia('print');
      const toast = useToast();
      const doCheckNames = React.useCallback((verId: string) => {
        const result = assertNamesUnique([{value: rep?.tzFields},
          {value: config设备概况, type:'esnt'},
          {value:['Projects', ]}
        ]);
        toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
      }, [rep,toast]);
      const {storage, setStorage} =React.useContext(EditStorageContext) as any;
      const getInpFilter = React.useCallback((par: any) => {
        const {_tblFixed, } =par||{};
        return {_tblFixed, };
      }, []);
      const {inp, setInp} = useItemInputControl({ref});
      if (atPrint) return null;
      else return (
          <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                               alone={alone} label={'初始化本报告，默认值配置等'}>
            {process.env.REACT_APP_TEST==='true' && <><div>
              <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
              <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
              <Text variant="h5">设置待测试表格的各列宽度：</Text>
              <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                JSON.parse(e.currentTarget.value??'[]');
                setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
            </div></>
            }
            <hr/>
          </InspectRecordLayout>
      );
    });



const recordPrintList =[
  createItem('Entrance', <EntranceSetup/>),
  createItem('Survey', <DeviceSurvey config={config设备概况} label={'特种设备制造监督检验证书'}/>),
];

export const OriginalView=
  React.forwardRef((
    { action: modAction,  verId, repId='', rep}
    :OriginalViewProps, ref
  ) => {
    const {list}=useRecordListSubr(ref,rep,recordPrintList,modAction,verId);
    return <React.Fragment>
      {list}
    </React.Fragment>;
  } );
